

from turtle import Screen, Turtle
import random

screen = Screen()

def itree(t, l, f, colors):
    t.color(colors[0])#se repite dependiendo cauntos colores se pasan por parametros
    t.forward(l)
    l1 = l
    turtles = [t]
    colors.pop(0)
    while colors:
        f = random.uniform(0.3, 0.7) #genera rama de forma aleatoria 
        l *= f
        l1 *= f
        newturtles = []
        for t in turtles:
            t.color(colors[0])
            t1 = t.clone()
            angle1 = random.randint(30, 60) #en cada nueva rama cambia el angulo
            angle2 = random.randint(30, 60)
            t.left(angle1)
            t.forward(l)
            t1.right(angle2)
            t1.forward(l1)
            newturtles.extend([t, t1])
        turtles = newturtles
        colors.pop(0)
    for t in turtles:
        t.color("green")
            
def main():
    screen.mode("logo")
    t = Turtle()#shape="turtle"
    t.shapesize(1, 1, 1)  
    leaflong = random.uniform(0.3, 0.7)
    t.penup(); t.back(280); t.pendown()
    t.pensize(2)
    itree(t, 270, leaflong,
          ["black", "brown", "red", "orange", "violet", "lightblue"])
    return "Done!"

if __name__ == '__main__':
    
    main()
    screen.mainloop()
    screen.bye()
